package com.huashi.dealer.modular.controller.store.market;

import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.modular.business.category.param.GiftCategorySaveParam;
import com.huashi.dealer.modular.business.category.service.GiftCategoryService;
import com.huashi.dealer.modular.business.category.vo.GiftCategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Store端赠品分类管理")
@RestController("storeMarketGiftCategoryController")
@RequestMapping("/store/market/category")
@Validated
public class GiftCategoryController {

    @Resource
    private GiftCategoryService giftCategoryService;

    @GetMapping("/list")
    @Operation(summary = "获取赠品分类树形列表")
    public CommonResult<List<GiftCategoryVo>> getGiftCategoryList() {
        List<GiftCategoryVo> list = giftCategoryService.getGiftCategoryTree();
        return CommonResult.data(list);
    }

    @PostMapping("/save")
    @Operation(summary = "新增或编辑赠品分类")
    public CommonResult<String> saveCategory(@RequestBody GiftCategorySaveParam param) {
        giftCategoryService.saveOrUpdateCategory(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/delete/{categoryId}")
    @Operation(summary = "删除赠品分类")
    public CommonResult<String> deleteCategory(@PathVariable Long categoryId) {
        giftCategoryService.deleteCategory(categoryId);
        return CommonResult.ok("删除成功");
    }

    @GetMapping("/detail/{categoryId}")
    @Operation(summary = "获取赠品分类详情")
    public CommonResult<GiftCategoryVo> getCategoryDetail(@PathVariable Long categoryId) {
        GiftCategoryVo detail = giftCategoryService.getCategoryDetail(categoryId);
        return CommonResult.data(detail);
    }
}
